package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.bean.vo.wx.wxuserindex.WXUserIndexTotalVo;
import com.cskaoyan.service.wx.WXUserIndexService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Yan Dexuan
 * @since 2022/06/28 19:25
 */
@RestController
@RequestMapping("wx/user")
public class WXUserIndexController {

    @Autowired
    WXUserIndexService wxUserIndexService;

    /**
     * 微信小程序个人中心首页，显示待付款，待发货，待收货，待评价等订单数据信息。
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author Yan Dexuan
     * @since 2022/06/28 22:05 
     */
    @RequestMapping("index")
    public BaseRespVo userIndex(){

        MarketUser marketUser = new MarketUser();
        marketUser.setId(0);
        Subject subject = SecurityUtils.getSubject();
        PrincipalCollection principals = subject.getPrincipals();

        if (!ObjectUtils.isEmpty(principals)){
            marketUser = (MarketUser) principals.getPrimaryPrincipal();
        }

        WXUserIndexTotalVo wxUserIndexTotalVo = wxUserIndexService.useIndex(marketUser);

        return BaseRespVo.ok(wxUserIndexTotalVo);

    }

}
